import numpy as np
from json import JSONEncoder
class NumpyEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)  # 将 numpy.int64 转换为 Python int
        elif isinstance(obj, np.floating):
            return float(obj)  # 将 numpy.float64 转换为 Python float
        elif isinstance(obj, np.ndarray):
            return obj.tolist()  # 将 numpy 数组转换为列表
        return super().default(obj)